package com.lzc.mis.lab.controller;

import com.lzc.mis.pos.entity.PosCategory;
import com.lzc.mis.pos.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author <l_haha@outlook.com>
 * @version 1.0.0
 * @ClassName com.lzc.mis.web.controller.lab.controller.CategoryController.java
 * @createTime 2021 09 24
 * @Description TODO
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 分页查询
     * @param posCategory 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public List<PosCategory> list(PosCategory posCategory) {
        return this.categoryService.queryAll(posCategory);
    }

    /**
     * 通过主键查询单条数据
     * @param categoryId 主键
     * @return 单条数据
     */
    @GetMapping("{categoryId}")
    public PosCategory getById(@PathVariable("categoryId") Integer categoryId){
        return this.categoryService.queryById(categoryId);
    }

    /**
     * 增加数据
     * @param posCategory
     * @return
     */
    @PostMapping
    public String add(@RequestBody PosCategory posCategory){
        this.categoryService.insert(posCategory);
        return "插入成功";
    }

    /**
     * 编辑数据
     * @param posCategory 实体
     * @return 编辑结果
     */
    @PutMapping
    public String edit(@RequestBody PosCategory posCategory){
        this.categoryService.update(posCategory);
        return "编辑成功";
    }

    /**
     * 删除数据
     * @param categoryId 主键id
     * @return
     */
    @DeleteMapping("/delete/{categoryId}")
    public Boolean deleteById(@PathVariable Integer categoryId){
        return this.categoryService.deleteById(categoryId);
    }





}
